package com.blog.controller.frontpage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.blog.controller.base.BaseServlet;
import com.blog.entity.ArticleConstraintEntity;
import com.blog.entity.DiscussConstraintEntity;
import com.blog.entity.TypesEntity;
import com.blog.service.frontpage.ArticleService;
import com.blog.service.frontpage.DiscussService;
import com.blog.service.frontpage.IndexService;

@WebServlet("/detail")
public class DetailServlet extends BaseServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 1、查询分类
		IndexService service = new IndexService();
		List<TypesEntity> typesList = service.getAllTypesInfo();
		req.setAttribute("typesList", typesList);
		
		//2、根据标题查询文章详情
		String titleid = req.getParameter("titleid");
		req.getSession().setAttribute("titleid", titleid);
		ArticleService articleService = new ArticleService();
		ArticleConstraintEntity articleByTitle = articleService.getArticleByTitle(titleid);
		req.setAttribute("articleByTitle", articleByTitle);
		
		//3、查询评论数据
		DiscussService discussService = new DiscussService();
		List<DiscussConstraintEntity> queryAllDisscuss = discussService.queryAllDiscuss(Integer.parseInt(titleid));
		req.setAttribute("queryAllDisscuss",queryAllDisscuss );
		
		//4、点击查看详情增加浏览量
		int updateReadNumber = articleService.updateReadNumber(Integer.parseInt(titleid));
		//System.out.println(updateReadNumber);
		
		forward("llpfrontpage/detail");
	}
}
